package com.caterina.activities;

import java.awt.Container;
import java.awt.GridLayout;
import java.util.Collection;

import com.caterina.activityManager.CActivity;
import com.caterina.components.CPanel;
import com.caterina.springBoard.Configuration;

import controllers.Permission;
import controllers.PermissionList;
import controllers.ManagerTask.TaskType;

public class SpringBoardActivity extends CActivity {
	public SpringBoardActivity(Container parent) {
		super("SPRINGBOARD_ACTIVITY_TITLE",parent);//Nome dell' activity
		super.setCBarVisible(true);
		super.setLogoutButtonVisible(true);
		super.setSbButtonVisible(false);
	}
	@SuppressWarnings("unchecked")
	@Override
	public void onData(TaskType task, Object data) {
		if (task==TaskType.USER_PERMISSIONS){
			this.permissions=new PermissionList((Collection<Permission>) data);
			GridLayout glut=new GridLayout(3,1);
			CPanel springContainer=new CPanel(glut);
			springContainer.add(new CPanel());
			CPanel spAnel=Configuration.getSpringPanel(this, permissions,this.getParentContainer());
			springContainer.add(spAnel);
			springContainer.add(new CPanel());
			this.add(springContainer);
		}
	}
	@Override
	public void onError(TaskType task, Exception e) {
		if (this.trys++<3)
			this.putTask(TaskType.USER_PERMISSIONS);
	}
	@Override
	public void onStart() {
		this.putTask(TaskType.USER_PERMISSIONS);
	}
	private int trys=0;
	private static final long serialVersionUID = 1L;
	private PermissionList permissions;
}
